<?php
/**
 * 加盟商即江湖结盟
 */
defined('InShopNC') or exit('Access Invalid!');

class franchiserControl extends BaseHomeControl
{
    /**
     * @var franchiserModel
     */
    protected $_model;
    public function __construct()
    {
        parent::__construct();
        //设置页面布局
        Tpl::setLayout('sj_home_layout');
        $this->_model = Model('franchiser');
    }

    /**
     * 江湖结盟首页
     */
    public function indexOp()
    {
        //查询所有商家
        Tpl::output('franchiser', $this->_model->getShowList());
        //查询商家文章
        Tpl::output('franchiserArticle', $this->_model->getArticleList());
        //面包屑导航
        Tpl::output('nav_link_list', array(
            array('link' => urlShop('index', 'index'), 'title' => '首页'),
            array('link' => urlShop('franchiser', 'index'), 'title' => '江湖结盟'),
        ));
        Tpl::showpage('sj_franchiser.index');
    }

    /**
     * 江湖结盟申请页
     */
    public function applyOp()
    {

        if ($_POST) {
            $insertData['franchisee_name']=$_POST['name'];
            $insertData['franchisee_address']=$_POST['jmdz'];
            $insertData['linkname']=$_POST['username'];
            $insertData['linkname_mobile']=$_POST['tel'];
            $insertData['areaid_1']=$_POST['province'];
            $insertData['areaid_2']=$_POST['city'];
            $insertData['linkname_email']=$_POST['email'];
            $insertData['liankname_qq']=$_POST['qq'];
            $insertData['linkname_tea_age']=$_POST['chacysj'];
            $insertData['linkname_puertea_age']=$_POST['prcysj'];
            $insertData['franchisee_goods']=$_POST['jycp'];
            $insertData['franchisee_area']=$_POST['mj'];
            $insertData['shujian_feelins']=$_POST['liaojie'];
            $insertData['franchinsee_plan']=$_POST['jyjh'];
            $s=$this->_model->addApply($insertData);
            if($s){
                echo '<script type="text/javascript">alert("申请成功，请等待我们与您联系");window.location.href="'.urlShop('index','index').'";</script>';
            }else{
                echo '<script type="text/javascript">alert("申请失败，请重试");window.history.back();</script>';
            }
        } else {
            //面包屑导航
            Tpl::output('nav_link_list', array(
                array('link' => urlShop('index', 'index'), 'title' => '首页'),
                array('link' => urlShop('franchiser', 'apply'), 'title' => '加盟申请'),
            ));
            Tpl::showpage('sj_franchiser.apply');
        }

    }
}